<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客注册页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/register.css">

</head>

<body>
    <div class="nav">
        <img src="pic/logo2.jpg" alt="">
        <span class="blog-title">我的博客系统</span>
        <div class="space"></div>
        <a class="nav-span" href="blog_list.html">主页</a>
        <a class="nav-span" href="blog_edit.html">写博客</a>
    </div>

    <div class="container-login">
        <div class="login-dialog">
            <h3>注册用户</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" name="username" id="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" name="password" id="password">
            </div>
            <div class="row">
                <span>确认密码</span>
                <input type="password2" name="password2" id="password2">
            </div>
            <div class="row">
                <button id="submit" onclick="register()">注册</button>
            </div>
            
        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script>
        function register() {
            // location.assign("blog_list.html");
            let username = document.querySelector('#username').value;
            let password = document.querySelector('#password').value;
            let password2 = document.querySelector('#password2').value;
            console.log(password)
            console.log(password2)
            if(username == "") {
                alert("用户名不能为空!");
            }
            if(password != password2) {
                alert("两次密码输入不一致!")
            }
            $.ajax({
                type:"post",
                url:"/user/register",
                data:{
                    username:username,
                    password:password
                },
                success:function(result) {
                    if(result.code == "SUCCESS") {
                        location.href = "blog_login.html";
                    }else{
                        alert(result.errMsg);
                    }
                }
            });
        }
    </script>
</body>

</html>